/**
 * 
 */
package org.skyeye.modeling.provider;

import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.skyeye.modeling.model.DevBean;
import org.skyeye.modeling.model.MachBean;
import org.skyeye.modeling.model.RegBean;

/**
 * @author Vivian
 * @date 2017-6-26
 */
public class DeviceTreeContentProvider implements ITreeContentProvider {


	@Override
	public Object[] getElements(Object element) {
		if (element instanceof List) {
			return ((List)element).toArray();
		}
		return new Object[0];
	}

	@Override
	public Object[] getChildren(Object element) {
		if(element instanceof MachBean) {
			return ((MachBean)element).getDevBeans().toArray();
		}else if(element instanceof DevBean) {
			return ((DevBean)element).getRegBeans().toArray();
		}
		return new Object[0];
	}

	@Override
	public Object getParent(Object element) {
		if(element instanceof DevBean) {
			return ((DevBean)element).getParent();
		}else if(element instanceof RegBean) {
			return ((RegBean)element).getParent();
		}
		return null;
	}
	
	@Override
	public boolean hasChildren(Object element) {
		if(element instanceof MachBean) {
			List<DevBean> devBeans = ((MachBean)element).getDevBeans();
			return devBeans != null && devBeans.size() > 0 ? true:false;
		}else if(element instanceof DevBean) {
			List<RegBean> regBeans = ((DevBean)element).getRegBeans();
			return regBeans != null && regBeans.size() > 0 ? true:false;
		}
		return false;
	}

	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {

	}

}
